﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutoPartsSearch.Domain.Abstract.Repositories;
using AutoPartsSearch.Domain.Entities;
using AutoPartsSearch.Web.Areas.Administration.Models.BlackList;
using AutoPartsSearch.Web.ViewModels;

namespace AutoPartsSearch.Web.Areas.Administration.Controllers
{
    public class BlackListController : BaseAdminController
    {
        private IBlackListRepository _repository;

        public BlackListController(IBlackListRepository repository)
        {
            this._repository = repository;
        }

        public ActionResult List(int page = 1, int pageSize = 20)
        {
            var result = _repository.Get(page, pageSize);
            var viewModel = new ViewModel()
                                {
                                    BlackLists = result,
                                    PagingInfo = new PagingInfo()
                                                     {
                                                         CurrentPage = page,
                                                         ItemsPerPage = pageSize,
                                                         TotalItems = _repository.GetTotalCount()
                                                     }
                                };
            return View(viewModel);
        }

        public ActionResult BySeller(string sellerCode, bool onlyApproved = false)
        {
            var result = _repository.GetBySellerCode(new Guid(sellerCode), onlyApproved);
            return View(result);
        }

        public ActionResult Details(int id)
        {
            var result = _repository.GetById(id);
            return View(result);
        }

        [HttpPost]
        public ActionResult Update(BlackList blackList)
        {
            _repository.Update(blackList);
            return RedirectToAction("List");
        }

    }
}
